import 'package:flutter/material.dart';

class BarVal {
  final String name;
  final double val;
  final String label;

  BarVal(this.name, this.val, this.label);
}

class BarItem extends StatelessWidget {
  final double height;
  final String label;
  final String val;

  final int _baseDurationMs = 1000;
  final double _maxElementHeight = 200;

  BarItem(this.height, this.label, this.val);

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final width1 = size.width - 160;
    final height1 = size.height;

    return Container(
        margin: const EdgeInsets.all(4.0),
        child: Row(
          children: <Widget>[
            Container(
              margin: const EdgeInsets.only(top: 8.0, bottom: 8.0),
              child: Text(label),
              width: 100.0,
            ),
            Container(
              height: 20,
              width: width1,
              color: Colors.blue,
            ),
            Container(
              width: (0) * width1,
            ),
            Container(
                margin: const EdgeInsets.all(2.0),
                width: 40.0,
                child: Center(child: Text(val))),
          ],
        ));
  }
}

class BarChart extends StatelessWidget {
  final List<BarVal> valList;
  final String title;
  BarChart(this.valList, this.title);

  List<Widget> getItems() {
    var xList = <Widget>[];
    xList.add(Text(title));
    for (int i = 0; i < valList.length; i++) {
      xList.add(BarItem(valList[i].val, valList[i].name, valList[i].label));
    }

    return xList;
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(2.0),
      child: Column(
        //mainAxisAlignment: MainAxisAlignment.center,
        // crossAxisAlignment: CrossAxisAlignment.center,
        //crossAxisAlignment: CrossAxisAlignment.baseline,
        children: this.getItems(),
      ),
    );
  }
}
